// -----------------------------------------------------------------------
//  <copyright file="IAuthorizationCache.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024/12/13 0:21</last-date>
// -----------------------------------------------------------------------

namespace DaprPlus.Authorization;

/// <summary>
/// 定义资源权限缓存功能，资源Id为键，角色及可执行操作的字典为值
/// </summary>
public interface IAuthorizationCache
{
    /// <summary>
    /// 创建资源权限缓存
    /// </summary>
    /// <returns></returns>
    Task BuildResourceAuthorizationCache();

    /// <summary>
    /// 获取或创建指定资源的权限缓存，资源Id为键，角色及可执行操作的字典为值
    /// </summary>
    /// <param name="resource">资源信息</param>
    /// <param name="forceRefresh">是否强制重建</param>
    /// <param name="scopedProvider">作用域服务提供者</param>
    /// <returns>角色权限配置集合</returns>
    Task<ResourceAuthCacheItem[]> GetOrBuildResourceAuthorizationCache(IResource resource,
        bool forceRefresh = false, IServiceProvider? scopedProvider = null);

    /// <summary>
    /// 移除指定资源的权限缓存
    /// </summary>
    /// <param name="resourceIds">资源编号</param>
    /// <returns></returns>
    Task RemoveResourceAuthorizationCache(params long[] resourceIds);

    /// <summary>
    /// 创建资源缓存
    /// </summary>
    /// <returns></returns>
    Task BuildResourceCache();

    /// <summary>
    /// 获取资源缓存
    /// </summary>
    /// <param name="code">资源码</param>
    /// <param name="type">资源类型</param>
    /// <param name="scopedProvider">区域服务提供者</param>
    /// <returns></returns>
    Task<IResource?> GetResourceCache(string code, ResourceType type, IServiceProvider? scopedProvider = null);

    /// <summary>
    /// 移除资源缓存
    /// </summary>
    /// <param name="code">资源码</param>
    /// <param name="type">资源类型</param>
    /// <returns></returns>
    Task<bool> RemoveResourceCache(string code, ResourceType type);
}
